<template>
  <aside class="category-sidebar">
    <div class="sidebar-header">
      <h3 class="sidebar-title">商品分类</h3>
    </div>
    <div class="sidebar-category" v-for="category in categories" :key="category.id" @click="handleCategoryClick(category)">
      <i :class="category.icon"></i>
      <span>{{ category.name }}</span>
    </div>
  </aside>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 分类数据
const categories = ref([
  { 
    id: 1, 
    name: '手机 / 数码 / 电脑', 
    icon: 'fas fa-mobile-alt',
    path: 'mobile-digital',
    subcategories: ['手机', '平板', '笔记本', '台式机', '配件']
  },
  { 
    id: 2, 
    name: '服饰 / 箱包 / 运动', 
    icon: 'fas fa-tshirt',
    path: 'fashion-sports',
    subcategories: ['男装', '女装', '童装', '箱包', '运动鞋']
  },
  { 
    id: 3, 
    name: '书籍 / 卡券 / 测试', 
    icon: 'fas fa-book',
    path: 'books-cards',
    subcategories: ['文学', '科技', '教育', '礼品卡', '优惠券']
  },
  { 
    id: 4, 
    name: '母婴 / 美妆 / 个护', 
    icon: 'fas fa-baby',
    path: 'baby-beauty',
    subcategories: ['奶粉', '尿布', '护肤品', '彩妆', '洗护']
  },
  { 
    id: 5, 
    name: '家具 / 家电 / 家装', 
    icon: 'fas fa-home',
    path: 'furniture-appliances',
    subcategories: ['沙发', '床垫', '冰箱', '洗衣机', '灯具']
  },
  { 
    id: 6, 
    name: '文玩 / 珠宝 / 礼品', 
    icon: 'fas fa-gem',
    path: 'jewelry-gifts',
    subcategories: ['手串', '项链', '戒指', '礼品', '收藏品']
  },
  { 
    id: 7, 
    name: '图书 / 游戏 / 音像', 
    icon: 'fas fa-gamepad',
    path: 'books-games',
    subcategories: ['小说', '教材', '游戏', '音乐', '电影']
  },
  { 
    id: 8, 
    name: '汽车 / 电动车 / 租房', 
    icon: 'fas fa-car',
    path: 'auto-rental',
    subcategories: ['汽车', '电动车', '摩托车', '租房', '车位']
  },
  { 
    id: 9, 
    name: '五金 / 设备 / 农牧', 
    icon: 'fas fa-tools',
    path: 'hardware-agriculture',
    subcategories: ['工具', '机械', '种子', '肥料', '农药']
  }
])

// 分类点击处理
const handleCategoryClick = (category: any) => {
  router.push(`/category/${category.path}`)
}
</script>

<style scoped>
.category-sidebar {
  width: 200px;
  background: white;
  border-radius: 12px;
  padding: 24px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  height: fit-content;
  min-height: calc(100vh - 200px);
  position: sticky;
  top: 100px;
  flex-shrink: 0;
  z-index: 10;
  margin-right: 20px;
  max-width: 200px;
  align-self: stretch;
}

.sidebar-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f1f3f4;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 600;
  color: #2d3436;
  margin: 0;
  text-align: center;
}

.sidebar-category {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-category:last-child {
  margin-bottom: 0;
}

.sidebar-category:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: translateX(4px);
}

.sidebar-category:hover::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 0 2px 2px 0;
}

.sidebar-category i {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.3s ease;
}

.sidebar-category:hover i {
  transform: scale(1.1);
}

.sidebar-category span {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  line-height: 1.4;
  color: #2d3436;
}

@media (max-width: 768px) {
  .category-sidebar {
    width: 100%;
    position: static;
    order: 2;
    margin-right: 0;
    margin-bottom: 20px;
    max-width: 100%;
    min-height: auto;
    padding: 20px 16px;
  }
  
  .sidebar-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
  }
  
  .sidebar-title {
    font-size: 16px;
  }
  
  .sidebar-category {
    padding: 12px 14px;
    margin-bottom: 8px;
  }
  
  .sidebar-category span {
    white-space: normal;
    font-size: 14px;
  }
  
  .sidebar-category i {
    width: 20px;
    height: 20px;
    font-size: 14px;
  }
}
</style> 